// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

// import {toolActionList} from "./toolMediator";

const {ccclass, property} = cc._decorator;

export enum toolList{
    noAction = 0,
    openSwitch = 1,
    portal = 2,
    repeatSwitch = 3,
    sceneReversal = 4,
    showEggWindow = 5,
    showStoneWindow = 6,
    showGetEgg = 7,
    showPetPrince8 = 8,
    showSkinPrince8 = 9,
    showQuestionPrince8 = 10,
    seeThreadPrince8 = 11,
    showScissor = 12,
    showSword = 13

}

@ccclass
export default class handControl extends cc.Component {

    @property({displayName : "点完手是否消失"})
    disappear : boolean = true;

    curHandAction = null;

    curCheckTarget = null;

    onLoad(){
        cc.game.on("setHandAction",(action,target)=>{
            this.curHandAction = action;
            this.curCheckTarget = target;
        });
        this.node.getChildByName("bg").active = false;
    }

    protected onEnable() : void {
        this.node.on("touchstart",this.showBg,this);
        this.node.on("touchend",this.showBg,this);
        this.node.on("touchend",this.playEvent,this);
    }

    protected onDisable(): void {
        this.node.off("touchend",this.playEvent,this);
    }

    showBg(){
        this.node.getChildByName("bg").active = true;
    }

    playEvent(event){
        this.node.getChildByName("bg").active = false;
        this.playAction();
    }

    //玩家动作列表
    playAction(){
        switch (this.curHandAction) {
            case toolList.noAction :
                console.log("无动作");
                break;
            case toolList.openSwitch :
                cc.game.emit("toolAction",toolList.openSwitch);
                break;
            case toolList.portal :
                cc.game.emit("toolAction",toolList.portal);
                break;
            case toolList.repeatSwitch :
                cc.game.emit("toolAction",toolList.repeatSwitch);
                break;
            case toolList.sceneReversal:
                cc.game.emit("toolAction",toolList.sceneReversal);
                break;
            case toolList.showEggWindow:
                cc.game.emit("toolAction",toolList.showEggWindow);
                break;
            case toolList.showStoneWindow:
                cc.game.emit("toolAction",toolList.showStoneWindow);
                break;
            case toolList.showGetEgg:
                cc.game.emit("toolAction",toolList.showGetEgg);
                break;
            case toolList.showPetPrince8:
                cc.game.emit("toolAction",toolList.showPetPrince8);
                break;
            case toolList.showQuestionPrince8:
                cc.game.emit("toolAction",toolList.showQuestionPrince8);
                break;
            case toolList.showSkinPrince8:
                cc.game.emit("toolAction",toolList.showSkinPrince8);
                break;
            case toolList.showScissor:
                cc.game.emit("toolAction",toolList.showScissor);
                break;
            case toolList.showSword:
                cc.game.emit("toolAction",toolList.showSword);
                break;
            case toolList.seeThreadPrince8:
                cc.game.emit("toolAction",toolList.seeThreadPrince8);
                break;
        }
        if(this.disappear){
            this.node.active = false;
        }
    }
}
